home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Peripherals / MacinTalk / Example Programs / Say Source / say.p < prev   
Text File  |  1989-04-13  |  3KB  |  129 lines

  1. {
  2.     say - a sample program illustrating the use of MacinTalk
  3.               in a MPW tool.  This tool will route standard input
  4.               through MacinTalk.
  5.  
  6.     disclaimer: this program was written hastely and should
  7.                             not be thought of as a very good example
  8.  
  9.     parameters:
  10.         -d        debug = on
  11.         -m        mode = robotic
  12.         -r n    rate = n
  13.         -p n    rate = p
  14.  
  15.     example usage:
  16.         Directory | say        
  17.         
  18.         by Paul Mercer, 3/86
  19.         modified 7/87 for inclusion in MacinTalk 1.31 release
  20. }
  21.  
  22.  
  23. PROGRAM    say;
  24.  
  25. USES
  26.     MemTypes, QuickDraw, OSIntf, ToolIntf, PasLibIntf, IntEnv, Signal,
  27.     SpeechIntf;    {Macintalk interface}
  28.  
  29. VAR
  30.     instr:            str255;
  31.     theSpeech:    SpeechHandle;  {handle to speech globals}
  32.     SErr:                SpeechErr;
  33.     output:            Handle;        {handle to phonetic string}
  34.     debug:            boolean;
  35.     theMode:        F0Mode;
  36.  
  37.  
  38. PROCEDURE SayIt;
  39.  
  40. BEGIN
  41.     IF debug THEN
  42.         WriteLn('converting text to phonemes');
  43.     SErr := Reader(theSpeech, pointer(ORD4(@instr)+1), ORD(instr[0]), output);
  44.     IF debug THEN
  45.         WriteLn('speaking the phonemes');
  46.     SErr := MacinTalk(theSpeech, output);        {say it.}
  47. END; {SayIt}
  48.  
  49.  
  50. PROCEDURE MyExit;
  51.  
  52. BEGIN
  53.     IF debug THEN
  54.         WriteLn('closing Macintalk');
  55.     SpeechOff(theSpeech);                        {close the speech driver.}
  56.     DisposHandle(output);                        {release the output handle}
  57. END; {MyExit}
  58.  
  59.  
  60. PROCEDURE str2int(instr: str255; VAR inInt: integer);
  61.  
  62. VAR
  63.     i,j:    Integer;
  64.  
  65. BEGIN
  66.     j := 1;
  67.     inInt := 0;
  68.     FOR i := ORD(instr[0]) DownTo 1 DO
  69.     BEGIN
  70.         inint := inint + (j * (ORD(instr[i]) - ORD('0')));
  71.         j := j*10;
  72.     END;
  73. END; {str2Int}
  74.  
  75.  
  76. { main program starts here }
  77. VAR
  78.     x,y:    integer;
  79.  
  80. BEGIN
  81.     SErr := SpeechOn(noExcpsFiles, theSpeech);            {Open the speech driver}
  82.     IF SErr <> 0 THEN WriteLn('Error opening Macintalk: ', SErr);
  83.     theMode := Natural;
  84.     SpeechPitch(theSpeech, 0, theMode);
  85.     debug := False;
  86.     FOR x := 0 to ArgC-1 DO
  87.         BEGIN
  88.             IF (ArgV^[x]^ = '-d') or (ArgV^[x]^ = '-D') THEN
  89.                 debug := True;
  90.     
  91.             IF (ArgV^[x]^ = '-M') or (ArgV^[x]^ = '-m') THEN
  92.                 BEGIN
  93.                     IF debug THEN
  94.                         WriteLn('mode is Robotic');
  95.                     theMode := Robotic;
  96.                     SpeechPitch(theSpeech, 0, theMode);
  97.                 END;
  98.  
  99.             IF (ArgV^[x]^ = '-r') or (ArgV^[x]^ = '-R') THEN
  100.                 BEGIN
  101.                     str2int(ArgV^[x+1]^, y);
  102.                     IF debug THEN WriteLn('rate is: ', y);
  103.                     SpeechRate(theSpeech, y);
  104.                 END;
  105.  
  106.             IF (ArgV^[x]^ = '-p') or (ArgV^[x]^ ='-P') THEN
  107.                 BEGIN
  108.                     str2int(ArgV^[x+1]^, y);
  109.                     IF debug THEN WriteLn('pitch is: ', y);
  110.                     SpeechPitch(theSpeech, y, NoChange);
  111.                 END
  112.         END; {FOR x}
  113.  
  114. IF debug THEN
  115.     WriteLn('now disabling signals.');
  116. SErr := IEsighold(SIGALLSIGS);    {disable signals}
  117.  
  118. output := NewHandle(0);
  119.     REPEAT
  120.         BEGIN
  121.             IF debug THEN
  122.                 WriteLn('awaiting input');
  123.             ReadLn(instr);
  124.             SayIt;
  125.         END
  126.     UNTIL EOF;
  127.     MyExit;
  128. END.
  129.